package com.asia5b.a5mall.goods.adapter

import android.widget.ImageView
import android.widget.TextView
import com.asia5b.a5mall.goods.R
import com.asia5b.a5mall.middleware.model.shop.AbsGoodsModel

import com.asia5b.a5mall.middleware.utils.CurrencyPriceBuilder3
import com.asia5b.a5mall.middleware.utils.WImageLoader
import com.asia5b.a5mall.middleware.utils.judge
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * Created by zhangyuncai on 2020/1/11.
 */
class SearchGoodsAdapter(list: ArrayList<AbsGoodsModel>, var isMulti: Boolean) :
        BaseQuickAdapter<AbsGoodsModel, BaseViewHolder>(
                (isMulti).judge(R.layout.goodsitem_searchgoods_multi, R.layout.goodsitem_searchgoods),
                list) {
    init {
        addChildClickViewIds(R.id.iv_searchgoods_addcart)
    }
    override fun convert(helper: BaseViewHolder, item: AbsGoodsModel) {
        if (isMulti) {
            multi(helper, item)
        } else {
            single(helper, item)
        }
    }

    fun single(helper: BaseViewHolder, item: AbsGoodsModel) {
        //图片
        val iv_searchgoods_img = helper.getView<ImageView>(R.id.iv_searchgoods_img)
        WImageLoader.displayRoundImage(item.absGoodsImageUrl, iv_searchgoods_img,10)
        //商品名
        helper.setText(R.id.tv_searchgoods_goodsname, item.absGoodsName)
        //价格
        val tv_searchgoods_price = helper.getView<TextView>(R.id.tv_searchgoods_price)
        CurrencyPriceBuilder3().run {
            textView = tv_searchgoods_price
            price = item.absGoodsPrice
            priceList = item.absGoodsPriceList
            build14_18()
        }
        //销量
        helper.setText(R.id.tv_searchgoods_buycount, item.absGoodsSellCountText)
        //店铺名
        helper.setText(R.id.tv_searchgoods_shopname, item.absGoodsShopName)

    }

    fun multi(helper: BaseViewHolder, item: AbsGoodsModel) {
        //图片
        val iv_shophome_img = helper.getView<ImageView>(R.id.iv_shophome_img)
        WImageLoader.displayImage(item.absGoodsImageUrl, iv_shophome_img)
        //商品名
        helper.setText(R.id.iv_shophome_goodsname, item.absGoodsName)
        //价格
        val tv_shophome_newprice = helper.getView<TextView>(R.id.tv_shophome_newprice)
        CurrencyPriceBuilder3().run {
            textView = tv_shophome_newprice
            price = item.absGoodsPrice
            priceList = item.absGoodsPriceList
            build14_18()
        }
        //销量
        helper.setText(R.id.tv_shophome_buycount, item.absGoodsSellCountText)
        //店铺名
        helper.setText(R.id.tv_searchgoods_shopname, item.absGoodsShopName)
    }

}